import java.util.*;
import java.io.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class code2 {
    public static Read in = new Read();
    public static void main(String[] args) throws IOException {
        int n = in.nextInt(), m = in.nextInt();
        long[][] arr = new long[n][m];//long类型
        long[] row = new long[n];//每一行的和
        long[] col = new long[m];//每一列的和

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = in.nextLong();
                row[i] += arr[i][j];
                col[j] += arr[i][j];
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                System.out.print(row[i] + col[j] - arr[i][j] + " ");
            }
            System.out.println("");
        }
    }
}

class Read {
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}